import React, { PureComponent } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, Popconfirm, Switch, message, Upload, Icon, Dropdown, Menu, Divider, Drawer, Button, Form, Input, Badge, Modal, Table, Descriptions } from 'antd';
import { BaseForm, PromotionChannelsForm } from '@/components/FormTools';
import { queryChannelList, deleteData } from '@/services/auth';
import { secMap } from '@/configs/api.map';
import { getAllCity } from '@/services/auth';
import { StandardTable, SearchForm } from '@joy/joy-pro';
import { getValue, to } from '@/utils/smallTool';
import { connect } from 'dva';
import styles from './index.less';
import configData from './config-data';

const pageInfo = { showSizeChanger: true, showQuickJumper: true, defaultPageSize: 10 };
const drawerWidth = 500;
const formProp = {
  labelCol: { span: 6 },
  wrapperCol: { span: 18 },
};
@connect(({ global, loading, allcity, decrypt, authority }) => ({
  tableData: decrypt.tableData,
  IssueChannelList: decrypt.IssueChannelList,
  SalespersonList: decrypt.SalespersonList,
  ManufactureList: decrypt.ManufactureList,
  cityList: allcity.cityList,
  searchForm: decrypt.searchForm,
  permissionsList: authority.permissionsList,
  tableLoading: loading.effects['decrypt/decryptCard'],
  watermarkConfig: global.watermarkConfig,
}))
class Decrypt extends PureComponent {
  constructor(props) {
    super(props);
    this.$drawerForm = React.createRef();
    this.state = {
      resultDate: [],
      inputConfig: configData.getSearchInputConfig(props.cityList),
    };
    this.getSelectList();
  }
  /**
   * @description 条件筛选 [搜索]
   * @author zhe
   * @date 2020-04-13
   * @param {*} formData
   * @param {*} reaclData
   * @param {*} isClear
   * @memberof
   */
  actionSearch = (formData, reaclData, isClear) => {
    this.getQueryList(formData);
  };

  /**
   * @description 请求列表数据
   * @author zlh
   * @date 2021-10-18
   * @param {*} params
   * @memberof
   */
  getQueryList = (params = {}) => {
    const type = 'decrypt/decryptCard';
    const { dispatch } = this.props;
    dispatch({
      type,
      payload: params,
    });
  };

  /**
   * @description 请求事件类型下拉列表数据
   * @author zhe
   * @date 2020-04-14
   * @memberof
   */
  getSelectList = async () => {
    const type = 'allcity/getCityByPage';
    const { dispatch } = this.props;
    const cityList = await dispatch({
      type
    });
    this.setState({
      inputConfig: configData.getSearchInputConfig(cityList)
    })
  };
  /**
   * @description table操作触发改变事件
   * @author songs
   * @date 2019-07-12
   * @param {*} pagination
   * @param {*} filtersArg
   * @param {*} sorter
   * @memberof managementUser
   */
  handleStandardTableChange = (pagination, filtersArg, sorter, actionType) => {
    const { pageSize, current } = pagination;
    const pageNum = current;
    const pageRequest = { pageSize, pageNum };
    this.getQueryList(filtersArg, pageRequest);
  };
  tableCol = () => {
    return configData.getTableConfig();
  };

  render() {
    const { tableCol } = this;
    const { resultDate, inputConfig } = this.state;
    const { tableLoading, watermarkConfig, tableData } = this.props;
    const { list = [], pagination = {} } = tableData;
    return (
      <div>
        <PageHeaderWrapper title="" className="hasContent">
          <div style={{ background: '#fff', padding: '20px 0px 0px 24px', marginBottom: '10px' }}>
            <SearchForm
              defaultInput={inputConfig.slice(0, 3)}
              moreInput={inputConfig.slice(3)}
              gutter={{ md: 10 }}
              useCol={{ sm: 24, md: 12, xl: 8, xxl: 8 }}
              onSearch={this.actionSearch}
            ></SearchForm>
          </div>
          <Card bordered={false}>
            <StandardTable
              isWatermark
              watermark={{ ...watermarkConfig }}
              dataSource={list}
              pagination={{ ...pagination, ...pageInfo }}
              columns={tableCol()}
              loading={tableLoading}
              rowKey={(record, index) => index}
              onChange={($pagination, filtersArg, sorter) => {
                this.handleStandardTableChange($pagination, this.state.params, sorter, 'decrypt/decryptCard');
              }}
            ></StandardTable>
          </Card>
        </PageHeaderWrapper>
      </div>
    );
  }
}

export default Decrypt;
